<%--
  Created by IntelliJ IDEA.
  User: ttxs
  Date: 2023/7/31
  Time: 8:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fm" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/statics/js/jquery.min.js"></script>
    <script>
        $(function () {
            $.getJSON('${pageContext.request.contextPath}/roles/getAll', function (result) {
                for(let role of result) {
                    if (role.id == '${user.roleId}') {
                        $("[name=roleId]").append("<option selected value='" + role.id + "'>" + role.roleName + "</option>")
                    } else {
                        $("[name=roleId]").append("<option value='" + role.id + "'>" + role.roleName + "</option>")
                    }
                }
            })
        })
    </script>
</head>
<body>
<jsp:include page="/WEB-INF/jsp/header.jsp"/>
<h1>修改</h1>
<fm:form action="${pageContext.request.contextPath}/users/update" modelAttribute="user" method="post" enctype="multipart/form-data">
<%--    <input type="hidden" name="id" value="${user.id}">--%>
 <%--   <fm:hidden path="id"/>--%>
<table>
    <tr>
        <td>ID</td>
        <td>
            <fm:input path="id"/>
        </td>
    </tr>
    <tr>
        <td>账号</td>
        <td>
            <fm:input path="account"/>
        </td>
    </tr>
    <tr>
        <td>生日</td>
        <td>
            <input type="date" name="birthday" value="<fmt:formatDate value="${user.birthday}" pattern="yyyy-MM-dd"/>">
        </td>
    </tr>
    <tr>
        <td>昵称</td>
        <td><fm:input path="realName"/></td>
    </tr>
    <tr>
        <td>角色</td>
        <td>
            <fm:select path="roleId">
                <fm:option value="" label="请选择"/>
<%--                <fm:options items="${roleList}" itemValue="id" itemLabel="roleName"/>--%>
            </fm:select>
           <%-- <select name="roleId">
                <option value="">请选择</option>
                <c:forEach var="item" items="${roleList}">
                    <option <c:if test="${item.id == user.roleId}">selected</c:if>  value="${item.id}">${item.roleName}</option>
                </c:forEach>
            </select>--%>
        </td>
    </tr>
    <tr>
        <td>身份证</td>
        <td>
            <input type="file" name="idPicPathFile">
            <img src="${uploadHost}/${user.idPicPath}" alt="身份证" width="32" height="32">
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input value="修改" type="submit">
            <input value="返回" type="button" onclick="location.href='${pageContext.request.contextPath}/users/list'">
        </td>
    </tr>
</table>
</fm:form>
</body>
</html>
